from construct_vect import construct_vect

from iw import get_wifi_rssi
import numpy as np
def get_curr_vector():
    aaa=get_wifi_rssi()
    f=open('mac_list.txt','r')
    file=f.read()
    new=file.split(',')
    mac_list=[]
    for tmp in new:
        tmp = tmp.replace('\'','')
        tmp = tmp.replace('[','')
        tmp = tmp.replace(']','')
        mac_list.append(tmp)
    curr_vector = construct_vect(aaa,mac_list)
    return curr_vector
def find_nearest_idx(vector_list,curr_vector):
    distance = sum(abs((vector_list[0])-(curr_vector)))
    idx=0
    i=0
    for vector in vector_list:
        
        tmp = sum(abs((vector)-(curr_vector)))
        if tmp<distance:
            idx=i
            distance=tmp
        i=i+1
    return idx

def get_curr_position()
    curr_vector = get_curr_vector()
    f=open('vector_list.txt','r')
    file=f.read()
    new=file.split(']')
    new_new=[]
    for tmp in new:
        tmp = tmp.replace('[','')
        new_new.append(tmp)
    vector_list=[]
    for tmp in new_new:
        if tmp:
            tmp = tmp.split(',')
            tmp=[i.replace('\'','') for i in tmp]
            tmp = [float(i) for i in tmp]
            vector_list.append(tmp)
    vector_list=np.array(vector_list,dtype='float64')
    curr_vector=np.array(curr_vector,dtype='float64')
    idx = find_nearest_idx(vector_list,curr_vector)
    print(idx)
    return idx

